#!/usr/bin/perl

# socket_test.pl: small script to test sockets
# done by: Sam Shannaq
#          www.phpspiders.com
# Create Date: 12-feb-2007
# Last Modified: 09-apr-2007
# Version: v0.01-beta
# Rev: 0000001

# This version may have been modified pursuant
# to the GNU General Public License, and as distributed it includes or
# is derivative of works licensed under the GNU General Public License or
# other free or open source software licenses.

use IO::Socket;
use strict;
use warnings;
use Getopt::Std;
use vars qw($opt_h $opt_p $opt_n);

getopts("h:p:n:");
die <<EOF
Socket Test v0.01-beta
Testing sockets using GET method , tested on IPv4 Only
Done by: Sam Shannaq (try on google)

This version may have been modified pursuant
to the GNU General Public License, and as distributed it includes or
is derivative of works licensed under the GNU General Public License or
other free or open source software licenses.

USAGE:
socket_test.pl -h ip_number -p port_number -n number_of_connections

-h: target ip to connection to
-p: port to connect to , default is 80 (webserver port) if NULL
-n: number of connections , default is 50 if NULL
EOF
unless $opt_h;

$opt_p ||= 80;
$opt_n ||= 50;

my @socks = ();

$| = 1;


for(0..$opt_n) {
  my($response);
  my($SOCKET) = new IO::Socket::INET( Proto   => "tcp",
                                      PeerAddr=> "$opt_h:$opt_p");
  if (! defined $SOCKET) { die $!; }
  print $SOCKET "GET /?$_ HTTP/1.0\n\n";
  $response = <$SOCKET>;
  print $response;
  close($SOCKET);
}
